package org.hxyjs.dao.impl;

import org.hxyjs.dao.IntegralDao;

import org.hxyjs.entity.Integral;
import org.hxyjs.mapper.IntegralMapper;
import org.hxyjs.page.PageInfo;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("integralDao")//一般实现类不会直接生成默认对象名 而是使用 接口的默认对象名
public class IntegralDaoImpl implements IntegralDao {
    @Resource //autowired 会装配能够直接扫描到的对象  resource spring容器运行的时候才找到需要的对象  注入
    private IntegralMapper integralMapper;
    public List<Integral>  getAllIntegrals() throws Exception{
        return integralMapper.selectByExample(null); }

    @Override
    public Integral getIntegralByUno(String inno) throws Exception {
        return integralMapper.selectByPrimaryKey(inno); }

    @Override
    public List<Integral> getIntegralsByPage(PageInfo pageInfo) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        int itemCount =(int) integralMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return integralMapper.getIntegralsByPage(map);
    }

    @Override
    public Integer deleteIntegral(String inno) { return integralMapper.deleteByPrimaryKey(inno); }

    @Override
    public Integer updateIntegral(Integral integral) { return integralMapper.updateByPrimaryKey(integral); }



    @Override
    public Integral getIntegralsWithOrders(String inno) throws Exception {
        return null;
    }

    @Override
    public Integral getAccountByAccountName(String inno) throws Exception {
        return null;
    }

    @Override
    public Integer addIntegralByUno(Integral integral){
        integral.setInno(initId());
        return integralMapper.insertSelective(integral);
    }
//
//    @Override
//    public Integral getIntegralsWithOrders(String inno) throws Exception {
//        return integralMapper.getIntegralsWithOrders(inno);
//    }
//    @Override
//    public Integral getAccountByAccountName(String uname) throws Exception {
//        return integralMapper.getAccountByAccountName(uname);
//    }
//
//
    public String initId() {
        String maxInno = integralMapper.getMaxInno();
        return org.hxyjs.utils.GenNumTools.initId("19", 4, maxInno);
    }
}
